package demo1;

import java.util.Stack;

public class Test {
    public static boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        int len = s.length();
        for(int i=0;i<len;i++) {
            char str = s.charAt(i);
            if(str == '(' || str == '[' || str == '{') {
                //入栈
                stack.push(str);
            } else {
                if(stack.empty()) {
                    return false;
                } else if(!(stack.pop() == str)) {
                    return false;
                }
            }
        }

        if(stack.empty()) {
            return true;
        }

        return false;
    }

    public static void main(String[] args) {
        char str = '1';

        isValid("()");
    }
    public static void main2(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        System.out.println(stack.size());
        System.out.println(stack.empty());
        System.out.println(stack.peek());
        System.out.println(stack.search(1));
        stack.pop();
        stack.pop();
        stack.pop();
        //System.out.println(stack.peek());
        stack.pop();
    }
    public static void display(MyStack stack) {
        for (int i = 0; i < stack.usedSize; i++) {
            System.out.print(stack.elem[i] + " ");
        }
        System.out.println();
    }

    public static void main1(String[] args) {
        MyStack stack = new MyStack();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        System.out.println(stack.pop());
        display(stack);
        System.out.println(stack.pop());
        display(stack);
        System.out.println(stack.isEmpty());
        System.out.println(stack.pop());
        display(stack);
        System.out.println(stack.isEmpty());
    }
}
